#include "PreCompiledHeader.h"
#include "GameStateMgr.hpp"
#include "GameState_Asteroid.hpp"
#include "SinglePlayer_Asteroid.hpp"
#include "GameState_Server.hpp"
#include "MainMenu.hpp"

// ---------------------------------------------------------------------------
// globals

// variables to keep track the current, previous and next game state
unsigned int	gGameStateInit;
unsigned int	gGameStateCurr;
unsigned int	gGameStatePrev;
unsigned int	gGameStateNext;

// pointer to functions for game state life cycles functions
void (*GameStateLoad)()		= 0;
void (*GameStateInit)()		= 0;
void (*GameStateUpdate)()	= 0;
void (*GameStateDraw)()		= 0;
void (*GameStateFree)()		= 0;
void (*GameStateUnload)()	= 0;

/**************************************************************************/
/*!
\brief
GSM init function
*/
/**************************************************************************/
void GameStateMgrInit(unsigned int gameStateInit)
{
	// set the initial game state
	gGameStateInit = gameStateInit;

	// reset the current, previoud and next game
	gGameStateCurr = 
	gGameStatePrev = 
	gGameStateNext = gGameStateInit;

	// call the update to set the function pointers
	GameStateMgrUpdate();
}

/**************************************************************************/
/*!
\brief
Update function whose main purpose is to set the appropriate function 
pointers to the diffrent game states
*/
/**************************************************************************/
void GameStateMgrUpdate()
{
	if ((gGameStateCurr == GS_RESTART) || (gGameStateCurr == GS_QUIT))
		return;

	switch (gGameStateCurr)
	{

	case GS_SINGLEPLAYER:
		GameStateLoad		=	SinglePlayerAsteroidsLoad;
		GameStateInit		=	SinglePlayerAsteroidsInit;
		GameStateUpdate		=  SinglePlayerAsteroidsUpdate;
		GameStateDraw		=  SinglePlayerAsteroidsDraw;
		GameStateFree		=  SinglePlayerAsteroidsFree;
		GameStateUnload		=  SinglePlayerAsteroidsUnload;
		break;

	case GS_ASTEROIDS:
		GameStateLoad		= GameStateAsteroidsLoad;
		GameStateInit		= GameStateAsteroidsInit;
		GameStateUpdate		= GameStateAsteroidsUpdate;
		GameStateDraw		= GameStateAsteroidsDraw;
		GameStateFree		= GameStateAsteroidsFree;
		GameStateUnload		= GameStateAsteroidsUnload;
		break;

	case GS_SERVER:
		GameStateLoad		= GameStateServerLoad;
		GameStateInit		= GameStateServerInit;
		GameStateUpdate		= GameStateServerUpdate;
		GameStateDraw		= GameStateServerDraw;
		GameStateFree		= GameStateServerFree;
		GameStateUnload		= GameStateServerUnload;
		break;
	
	case GS_MAINMENU:
		GameStateLoad		= MainMenuLoad;
		GameStateInit		= MainMenuInit;
		GameStateUpdate		= MainMenuUpdate;
		GameStateDraw		= MainMenuDraw;
		GameStateFree		= MainMenuFree;
		GameStateUnload		= MainMenuUnload;
		break;
	

	//default:
		//Invalid State!
	}
}
